package api

import (
	"pan/common/conf"
	"pan/common/exception"
	"pan/common/net"
	"pan/common/util"
)

type UserResponse struct {
	FailRsponse

	Account            string `json:"account"`
	AgreedToTermsOfUse bool   `json:"agreedtotermsofuse"`
	Userid             string `json:"userid"`
	Name               string `json:"name"`
	Mail               string `json:"mail"`
	CsfLevel           int64  `json:"csflevel"`
	Leakproofvalue     int    `json:"leakproofvalue"`
	Pwdcontrol         int    `json:"pwdcontrol"`
	UserType           int    `json:"usertype"`
	IsManager          bool   `json:"ismanager"`
	FreezeStatus       bool   `json:"freezestatus"`
	TelNumber          string `json:"telnumber"`
	NeedRealNameAuth   bool   `json:"needrealnameauth"`
	NeedSecondAuth     bool   `json:"needsecondauth"`
}

func UserApi(tokenid string) (*UserResponse, error) {
	url := util.PathJoin(conf.GlobalConfig.Url, conf.GlobalConfig.Paths.User)

	rsp := &UserResponse{}
	if err := net.PostWithToken(url, tokenid, nil, rsp); err != nil {
		return nil, err
	}
	if rsp.Errcode != 0 {
		return nil, exception.NewExpectError("user failed, %s", rsp.FailString())
	}
	return rsp, nil
}
